﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net.Core;
using log4net;

namespace Shsc.Net.FrameWork.Common.Log
{
    /// <summary>
    /// 
    /// </summary>
    public sealed class Log4NetLogger
    {
        private static ILog _logger = null;

        private Log4NetLogger(Type type)
        {
            _logger = LogManager.GetLogger(type.Name);
        }

        public static Log4NetLogger CreateLogger(Type type)
        {   
            return new Log4NetLogger(type);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        public void Debug(String message)
        {
            if (_logger.IsDebugEnabled)
            {
                _logger.Debug(message);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        public void Warn(String message)
        {
            if (_logger.IsWarnEnabled)
            {
                _logger.Warn(message);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        public void Info(String message)
        {
            if (_logger.IsInfoEnabled)
            {
                _logger.Info(message);
            }
        }
        
        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        /// <param name="ex"></param>
        public void Error(String message, Exception ex)
        {
            if (_logger.IsErrorEnabled)
            {
                _logger.Error(message, ex);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        /// <param name="ex"></param>
        public void Fatal(Exception ex)
        {
            if (_logger.IsFatalEnabled)
            {
                _logger.Fatal(String.Empty, ex);
            }
        }

        public bool IsDebugEnabled
        {
            get { return _logger.IsDebugEnabled; }
        }

        public bool IsErrorEnabled
        {
            get { return _logger.IsErrorEnabled; }
        }

        public bool IsFatalEnabled
        {
            get { return _logger.IsFatalEnabled; }
        }

        public bool IsInfoEnabled
        {
            get { return _logger.IsInfoEnabled; }
        }

        public bool IsWarnEnabled
        {
            get { return _logger.IsWarnEnabled; }
        }
    }
}
